package me.zhengjie.modules.management.rest.admin;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.management.domain.ConferenceRoom;
import me.zhengjie.modules.management.domain.Pageable;
import me.zhengjie.modules.management.service.ConferenceRoomService;
import me.zhengjie.modules.management.service.dto.ConferenceRoomQueryCriteria;
import me.zhengjie.utils.SecurityUtils;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

/**
 * @Author: yuchao.wang
 * @Date: 2020/12/7
 * @Description: 预约教室主表
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "MR:预约教室主表")
@RequestMapping("/api/conferenceRoom")
public class ConferenceRoomController {

    private final ConferenceRoomService conferenceRoomService;

    @GetMapping
    @Log("获取所有会议室信息")
    @ApiOperation("获取所有会议室类型信息")
    public Object getAllList(ConferenceRoomQueryCriteria conferenceRoomQueryCriteria, Pageable pageable){
        return  conferenceRoomService.findByCriteria(conferenceRoomQueryCriteria,pageable);
    }

    @GetMapping("/purposes")
    @Log("根据教室id获取对应的目的列表")
    @ApiOperation("根据教室id获取对应的目的列表")
    public Object getPurposesListByRoomId(Integer roomId){
        return  conferenceRoomService.findPurposeByRoomId(roomId);
    }


    @PostMapping
    @Log("新增会议室信息")
    @ApiOperation("新增会议室信息")
    public void addConferenceType(@RequestBody ConferenceRoom conferenceRoom){

        conferenceRoom.setCreateUserId(SecurityUtils.getCurrentUsername());
        conferenceRoom.setCreateDateTime(new Timestamp(new Date().getTime()));

        conferenceRoomService.create(conferenceRoom);
    }

    @PutMapping
    @Log("修改会议室信息")
    @ApiOperation("修改会议室信息")
    public void updateConferenceType(@RequestBody ConferenceRoom conferenceRoom){
        conferenceRoom.setModifyUserId(SecurityUtils.getCurrentUsername());
        conferenceRoom.setModifyDateTime(new Timestamp(new Date().getTime()));
        conferenceRoomService.update(conferenceRoom);
    }

    @DeleteMapping
    @Log("删除会议室信息")
    @ApiOperation("删除会议室信息")
    public void delConferenceRoomEquips(@RequestBody List<Integer> ids){
        conferenceRoomService.delete(ids);
    }


    @GetMapping(value = "/find")
    @Log("根据ID查询具体教室信息")
    @ApiOperation("根据ID查询具体教室信息")
    public Object getById(Integer roomId) {
        return conferenceRoomService.findById(roomId);
    }
}
